/**
 * 
 */
package de.nak.fireDepartment.dao;

import java.util.*;

import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import de.nak.fireDepartment.model.Department;

/**
 * Department data access object.
 * @author Sven Redelin
 */
public class DepartmentDAO extends HibernateDaoSupport {
	
	/**
	 * Finds and returns all Departments.
	 * @return a list of departments
	 */
	@SuppressWarnings("unchecked")
	public Collection<Department> findAll() {
		return (Collection<Department>)getHibernateTemplate().find("from Department");
	}
	
	/**
	 * Finds a Department with the given id.
	 * @param deptId The id.
	 * @return a Department object or <code>null</code>.
	 */
	public Department findById(Long deptId) {
		return (Department)getHibernateTemplate().get(Department.class, deptId);
	}
	
	/**
	 * Persists the given department object.
	 * @param department The department.
	 */
	public void save(Department department) {
		getHibernateTemplate().save(department);
	}
	
	/**
	 * Deletes the given department object.
	 * @param department The department.
	 */
	public void delete(Department department) {
		getHibernateTemplate().delete(department);
	}
}
